<template>
  <div>
    <el-page-header @back="goBack" content="详情页面"></el-page-header>
    <el-divider content-position="left">
      <p>组织机构</p>
    </el-divider>
    <el-form :model="dataForm" ref="dataForm" class="wds-form-top" label-width="150px">
      <el-row class="wds-frame">
        <el-row class="wds-el-row" type="flex">
          <el-col :span="12">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="组织机构" prop="name">
                <el-tag type="info" effect="plain">{{ dataForm.name }}</el-tag>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="创建者" prop="createUserId">
                <!--                {{ dataForm.createUserId }}-->
                <el-tag type="warning" effect="plain"><span>{{ getUserName(dataForm.createUserId) }}</span></el-tag>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-row class="wds-el-row" type="flex">
          <el-col :span="24">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="描述" prop="description">
                {{ dataForm.description }}
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-row class="wds-el-row" type="flex">
          <el-col :span="12">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="状态" prop="status">
                <el-tag v-if="dataForm.status===0" type="danger">禁用</el-tag>
                <el-tag v-else type="success">正常</el-tag>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="创建时间" prop="createTime">
                {{ dataForm.createTime }}
              </el-form-item>
            </div>
          </el-col>
        </el-row>
      </el-row>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dataForm: {
        name: '',
        createUserId: '',
        description: '',
        status: '',
        createTime: '',
      },
      UserListOptions: []
    };
  },

  created() {
    this.getUserList()
  },
  methods: {
    init(row) {
      this.dataForm = row;
    },
    goBack() {
      this.$emit('goBack');
    },

    // 获取用户列表
    getUserList() {
      this.$http({
        url: this.$http.adornUrl('/sys/user/list'),
        method: 'get',
        params: this.$http.adornData({})
      }).then(({data}) => {
        console.log('Response data:', data); // 添加调试信息
        if (data && data.code === 0) {
          this.UserListOptions = data.page.list.map(item => ({
            value: item.userId,
            label: item.realname
          }))
          console.log('User options:', this.UserListOptions);
        } else {
          console.error('Failed to fetch user list:', data.msg);
        }
      }).catch(error => {
        console.error('Error fetching user list:', error);
      })
    },

    getUserName(createUserId) {
      const orgname = this.UserListOptions.find(item => item.value === createUserId);
      return orgname ? orgname.label : '未分配';
    },
  },

};
</script>

<style>
.wds-form-top {
  margin-top: 8px;
}

.wds-frame {
  margin-left: 15px;
  margin-right: 15px;
  border-top: 1px solid rgba(184, 194, 215, 0.4);
  border-right: 1px solid rgba(184, 194, 215, 0.4);
}

.wds-frame-l {
  position: relative;
  width: 100%;
  height: 100%;
  border-left: 1px solid rgba(184, 194, 215, 0.4);
  border-bottom: 1px solid rgba(184, 194, 215, 0.4);
}

.wds-frame-form-item .el-form-item__label {
  padding-top: 6px;
  padding-left: 4px;
  line-height: 20px !important;
  width: 130px !important;
  color: #054999;
}

.wds-bj {
  width: 140px;
  border-right: 1px solid rgba(184, 194, 215, 0.4);
  height: 100%;
  position: absolute;
}

.wds-frame-form-item {
  max-height: 25px;
  padding-top: 6px;
  padding-left: 4px;
  line-height: 20px !important;
  color: #054999;
}

.el-divider .el-divider__text {
  font-size: 18px !important;
  font-weight: 800;
}
</style>
